<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图片上传预览 兼容ie6 ,ie7 ,火狐3.0</title>
<style type="text/css">
.img
{
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
</style>
<script type="text/javascript" language="javascript">
/*显示图片*/
function showpic(file,img){
 var dFile = document.getElementById(file.id);
 var dImg = document.getElementById(img);
 var dInfo = document.getElementById('img');
 
 if(!dFile.value.match(/.jpg|.gif|.png|.bmp/i)){
  alert('图片类型必须是: .jpg, .gif, .bmp or .png !');
  return;
 }
 if(dFile.files){
  dImg.src = dFile.files[0].getAsDataURL();
  
 }else{
	 /*这步骤是用来在ie6,ie7中显示图片的*/
	 var from=img.indexOf('g')+1;
	 var to=img.length;
	 var pic='pic'+img.substring(from,to);
	 var newPreview = document.getElementById(pic);
     newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dFile.value;
     dImg.style.display='none';
     newPreview.style.width = "105px";
     newPreview.style.height = "105px";
     
 }
}
</script>
</head>
<body>

<div id="pic1" class="img"></div>
<img id="img1" src="" width="105" height="104" />
<hr />
<p>请选择一个图片进行预览：<input type="file" id="upload3" name="upload" onchange="showpic(this,'img1');"/></p>
</body>
</html>










<p>
IE下的演示：

1
document.getElementById("upload").onchange = function() {
2
  document.getElementById("image").src = this.value;
3
}
FF下的演示：

1
document.getElementById("upload").onchange = function() {
2
  document.getElementById("image").src = this.files[0].getAsDataURL();
3
}


</p>